<?php
/**
 *============================================================================
 * Cornice PHP Framework & Website Builder
 * Freeware (f) 2011 by Inforo Software & Computer
 *============================================================================
 */
 
/**
 * Class for process cookies
 * @author Nicola Dinh
 * @version 2011.04.2316
 */
class cookie {

  /*
   * All properties
   */
  private static $cookies = array();

  /**
   * Default instance level constructor
   * Just decorative, should not be called due to having only static methods
   */
  public function __construct() {
    //
  }
  
  /**
   * Set a cookie value
   * @param string $name The name of cookie
   * @param string $vlaue The value of cookie
   */
  public static function set($name,$value) {
    $cookie_lifetime = config::get_config_value("cookie/lifetime");    
    setcookie($name,$value,time()+$cookie_lifetime,"/");
    self::$cookies[$name] = $value;
  }
  
  /**
   * Get a cookie value
   * @param string $name The name of cookie
   * @return string The value of cookie or 'null' if no such cookie
   */
  public static function get($name) {
    if (isset(self::$cookies[$name]))
      return self::$cookies[$name];
    else
    if (isset($_COOKIE[$name])) 
      return $_COOKIE[$name];
    else
      return null;
  }
}